package com.sdy.dcsb.web.controller;

import com.sdy.common.model.Response;
import com.sdy.dcsb.biz.model.EsbAtomlogReqJoint;
import com.sdy.dcsb.biz.service.EsbAtomlogReqService;
import com.sdy.mvc.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.List;
import static org.springframework.util.StringUtils.isEmpty;

/**
 * <p>
 * 原子服务报文日志表(请求和返回) 前端控制器
 * </p>
 *
 * @author fb
 * @since 2019-10-12
 */
@Slf4j
@Controller
@RequestMapping("/EsbAtomlogReq")
@Api(tags = "原子服务日志报文相关接口")
public class EsbAtomlogReqController extends BaseController {
    @Autowired
    private EsbAtomlogReqService esbAtomlogReqService;

    /**
     * 查询当前流水id的原子服务调用日志报文数据
     * @param reqid ,请求流水号
     * @return
     */
    @GetMapping("/selectDetailedMsg")
    @ResponseBody
    @ApiOperation("查询当前请求流水号的原子服务调用日志报文数据，精确查询")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "reqid", value = "请求流水号"),
    })
    public Response selectDetailedMsg(String reqid) {
        if(!isEmpty(reqid)) {
            try {
                reqid = URLDecoder.decode(reqid,"utf-8");
            }catch(IOException e) {

            }
            List<EsbAtomlogReqJoint> result = esbAtomlogReqService.findOneAtomServiceLogMsg(reqid);
            return Response.success(result);
        }else {
            return Response.error("请求流水号不能为空");
        }
    }

}
